#include <iostream>
#include "statistics.h"
#include "wordcounter.h"
#include "../Fakultet/hr_time.h"
#include "ordered_list.h"

using namespace std;

double rek_sum(int n)
{
	if (n <= 1)
		return 1.0;
	else
		return 1.0 / sqrt(n) + rek_sum(n - 1);
}

double sum(int n)
{
	double sum = 1;
	for (int i = 2; i <= n; i++)
	{
		sum += 1.0 / sqrt(i);
	}
	return sum;
}

void main3_1()
{
	for (int i = 0; i < 5; i++)
	{
		cout << rek_sum(i) << ", " << sum(i) << endl;
	}
}

void main3_2()
{
	if (SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS) == 0)
	{
		std::cout << "Error: SetPriorityClass: " << GetLastError() << endl;
	}
	if (SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL) == 0)
	{
		std::cout << "Error: SetThreadPriority" << endl;
	}
	CStopWatch w;
	w.startTimer();
	statistics s;
	s.read_from_file("salary.txt");
	cout << "Mean: " << s.calculate_mean() << endl;
	cout << "P25: " << s.percentile(25) << endl;
	cout << "P50: " << s.percentile(50) << endl;
	cout << "P75: " << s.percentile(75) << endl;
	cout << "P90: " << s.percentile(90) << endl;
	cout << "P99: " << s.percentile(99) << endl;
	w.stopTimer();
	cout.precision(8);
	cout << "elapsed time: " << 1e6*w.getElapsedTime() << endl;
}

void main3_3()
{
	wordcounter counter;
	counter.read_from_file("nils_holgersson.txt");
	counter.most_common();
	counter.top_twenty();
}

void main4_1()
{
	ordered_list ol(4);
	ol.print();
	ol.add("hej");
	ol.print();
	ol.add("apa");
	ol.print();
	ol.add("morgon");
	ol.print();
	ol.add("banan");
	ol.print();
	ol.add("kaka");
	ol.print();

	for (auto &s : ol)
	{
		cout << s.data << endl;
	}

	ol.clear();
	ol.print();
}

int main()
{
	//main3_1();
	main3_2();
	//main3_3();
	//main4_1();

	system("pause");
	return 0;
}